<!DOCTYPE HTML>
<html>
 <head>
  <title>Web Storage</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
 </head>
 <body>
    <h1>storage_local_setItem</h1>
    <div id="log"></div>
    <script>
        var test_error = { name: "test" };
        test(function() {
            localStorage.clear();
            test(function() {
                assert_false("name" in localStorage);
                assert_false("age" in localStorage);
            });
            test(function() {
                localStorage["name"] = "user1";
                assert_true("name" in localStorage);
                assert_equals(localStorage.length, 1, "localStorage.length")
                assert_equals(localStorage.getItem("name"), "user1");
                assert_equals(localStorage["name"], "user1");
            });
            test(function() {
                localStorage["name"] = "user2";
                assert_true("name" in localStorage);
                assert_equals(localStorage.length, 1, "localStorage.length")
                assert_equals(localStorage.getItem("name"), "user2");
                assert_equals(localStorage["name"], "user2");
            });
            test(function() {
                localStorage.setItem("name", "user3");
                assert_true("name" in localStorage);
                assert_equals(localStorage.length, 1, "localStorage.length")
                assert_equals(localStorage.getItem("name"), "user3");
                assert_equals(localStorage["name"], "user3");
            });
            test(function() {
                localStorage.setItem("age", null);
                assert_true("age" in localStorage);
                assert_equals(localStorage.length, 2, "localStorage.length")
                assert_equals(localStorage.getItem("age"), "null");
                assert_equals(localStorage["age"], "null");
            });
            test(function() {
                localStorage["age"] = null;
                assert_true("age" in localStorage);
                assert_equals(localStorage.length, 2, "localStorage.length")
                assert_equals(localStorage.getItem("age"), "null");
                assert_equals(localStorage["age"], "null");
            });
            test(function() {
                localStorage.setItem("age", undefined);
                assert_true("age" in localStorage);
                assert_equals(localStorage.length, 2, "localStorage.length")
                assert_equals(localStorage.getItem("age"), "undefined");
                assert_equals(localStorage["age"], "undefined");
            });
            test(function() {
                localStorage["age"] = undefined;
                assert_true("age" in localStorage);
                assert_equals(localStorage.length, 2, "localStorage.length")
                assert_equals(localStorage.getItem("age"), "undefined");
                assert_equals(localStorage["age"], "undefined");
            });
            test(function() {
                assert_throws(test_error, function() {
                    localStorage.setItem("age",
                        { toString: function() { throw test_error; } });
                });
                assert_true("age" in localStorage);
                assert_equals(localStorage.length, 2, "localStorage.length")
                assert_equals(localStorage.getItem("age"), "undefined");
                assert_equals(localStorage["age"], "undefined");
            });
            test(function() {
                assert_throws(test_error, function() {
                    localStorage["age"] =
                        { toString: function() { throw test_error; } };
                });
                assert_true("age" in localStorage);
                assert_equals(localStorage.length, 2, "localStorage.length")
                assert_equals(localStorage.getItem("age"), "undefined");
                assert_equals(localStorage["age"], "undefined");
            });
            test(function() {
                localStorage.setItem(undefined, "test");
                assert_true("undefined" in localStorage);
                assert_equals(localStorage.length, 3, "localStorage.length")
                assert_equals(localStorage.getItem("undefined"), "test");
                assert_equals(localStorage["undefined"], "test");
            });
            test(function() {
                localStorage[undefined] = "test2";
                assert_true("undefined" in localStorage);
                assert_equals(localStorage.length, 3, "localStorage.length")
                assert_equals(localStorage.getItem("undefined"), "test2");
                assert_equals(localStorage["undefined"], "test2");
            });
            test(function() {
                localStorage.setItem(null, "test");
                assert_true("null" in localStorage);
                assert_equals(localStorage.length, 4, "localStorage.length")
                assert_equals(localStorage.getItem("null"), "test");
                assert_equals(localStorage["null"], "test");
            });
            test(function() {
                localStorage[null] = "test2";
                assert_true("null" in localStorage);
                assert_equals(localStorage.length, 4, "localStorage.length")
                assert_equals(localStorage.getItem("null"), "test2");
                assert_equals(localStorage["null"], "test2");
            });
        });
    </script>
 </body>
</html>
